package com.ruyue.csinstall.command.impl;

import com.ruyue.csinstall.command.Command;
import com.ruyue.csinstall.model.CsPro;
import com.ruyue.csinstall.utils.FileTools;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.IOException;

/**
 * 无覆盖拷贝(即仅拷贝证书及渠道独有的配置文件)
 * @author xiawl
 * @create 2017/7/23 16:33.
 */
public class CpCommand implements Command{
    private static final Log log = LogFactory.getLog(CpCommand.class);
    private String backupConfPath;
    private String confPath;

    public CpCommand(CsPro csPro) {
        this.backupConfPath = String.format("%s/conf", csPro.getBackupPath());
        this.confPath = String.format("%s/comm-server", csPro.getUnZipPath());
    }

    @Override
    public boolean execute() {
        try {
            log.info(String.format("拷贝各app证书及个性化配置文件,从[%s]到[%s]相同目录下", backupConfPath, confPath));
            FileTools.cpNoOverlap(backupConfPath, confPath);
            log.info("各app证书及个性化配置文件拷贝完成");
            return true;
        } catch (IOException e) {
            log.error("证书及渠道个性化配置拷贝失败", e);
        }
        return false;
    }
}